package com.yy.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yy.common.result.PageResult;
import com.yy.common.result.Result;
import com.yy.entity.Register;
import com.yy.entity.Regiterlist;
import com.yy.entity.Report;
import com.yy.query.RegisterQuery;
import com.yy.service.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * @Author Yang
 * @Create 2024/6/15 10:02
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/discharge")
@Tag(name = "住院管理.出院结算")
public class DischargeController {
    //入院
    private final ReportService reportService;
    //住院表
    private final RegisterService registerService;
    //科室
    private final DepartmentsService departmentsService;
    //医生
    private final DoctorService doctorService;
    //床位
    private final BedService bedService;
    //预交表
    private final PayService payService;
    //药房表
    private final PharmacyService pharmacyService;
    //住院收费表
    private final HospitalpriceService hospitalpriceService;
    //住院项目收费表
    private final InoutpatienttypeService inoutpatienttypeService;

    @GetMapping("/pageResult")
    @Operation(summary = "出院结算分页查询")
    public PageResult<Regiterlist> pageResult(RegisterQuery registerQuery) {
        IPage<Regiterlist> page = registerService.alllistResister(registerQuery);
        return PageResult.success(page);
    }

    @PutMapping("/udregisterstate/{Hospitalizationnumber}")
    @Operation(summary = "结算出院改变状态并加入时间")
    public Result udregisterstate(@PathVariable Integer Hospitalizationnumber) {
        boolean f = registerService.update(new LambdaUpdateWrapper<Register>()
                .eq(Register::getRegisterid, Hospitalizationnumber)
                .set(Register::getState, 5)
                .set(Register::getEnddate, new Date()));
        return Result.success(f);
    }

    @GetMapping("/detail/{registerid}")
    @Operation(summary = "根据患者id查询是否有医保优惠")
    public Result Detail(@PathVariable int registerid){
        LambdaQueryWrapper<Register> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Register::getRegisterid,registerid);
        Register one = registerService.getOne(wrapper);
        return Result.success(one);
    }

}
